package com.hcr.action;


import java.util.List;

import javax.annotation.Resource;

import org.aspectj.weaver.patterns.ThisOrTargetAnnotationPointcut;
import org.springframework.stereotype.Component;

import com.hcr.commons.CurrentTime;
import com.hcr.model.Role;
import com.hcr.service.RoleService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
@Component("roleAction")
public class RoleAction extends ActionSupport implements ModelDriven<Role>{
	/**
	 * 
	 */
	private static final long serialVersionUID = -3097263067769033519L;
	private RoleService roleService;
	private Role role=new Role();
	public Role getRole() {
		return role;
	}
	public void setRole(Role role) {
		this.role = role;
	}
	public RoleService getRoleService() {
		return roleService;
	}
	@Resource(name="roleService")
	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}
	public String execute(){
		return "success";
	}
	public String addRole(){
		this.getRoles();
		return "add";
	}
	public String add(){
		this.role.setCreatetime(CurrentTime.getCurrentTime());
		this.roleService.addRole(role);
		return "showAll";
	}
	public String showAll(){
		this.getRoles();
		return "success";
	}
	public String deleteRole(){
		this.getRoles();
		return "deleterole";
	}
	public String delete(){
		this.roleService.deleteRole(role);
		return "showAll";
	}
	public void getRoles(){
		List<Role> roles=this.roleService.showAll();
		ActionContext context=ActionContext.getContext();
		context.put("roles", roles);
	}
	public String updateRole(){
		this.getRoles();
		return "update";
	}
	public String update(){
		System.out.println(role.getName());
		this.role.setCreatetime(CurrentTime.getCurrentTime());
		this.roleService.update(role);
		return "showAll";
	}
	public Role getModel() {
		return this.role;
	}
}
